<?php     
namespace app\api\model;

use think\Model;

class categroy_menu extends Model{
         
        protected $tableName = 'categroy_menu';
        protected $_auto = array(
            //根据id生成无限极的父子关系
            array('path','createPath',3,'callback'),
        );
        
        protected $_validate = array(
            array('name','require','栏目必须填!'),
        );
        
        protected function createPath(){
            
            $pid = isset($_GET['pid'])?$_GET['pid']:0;
            
            $path = $this->field('path,id')->where("id = $pid")->find();
            if(empty($path)){
                return  '0';
            }
            return $npath = $path['path'] . '-' . $path['id'];
        }
        

     }

?> 
